package cl.parser.internal;

import java.util.ArrayList;
import java.util.List;

import cl.parser.IParseNode;
import cl.parser.external.CloseParenNode;
import cl.parser.external.OpenParenNode;

public class ConditionNode extends InternalNode implements IFat {

    @Override
    public String prettyPrint(String indent) {
        return"(" + children.get(0).prettyPrint(indent) + ")";
    }
    
    @Override
    protected List<IParseNode> getAllowed(IParseNode last, List<IParseNode> soFar) {
        List<IParseNode> allowed = new ArrayList<IParseNode>();
        
        if(last == null) {
            allowed.add(new OpenParenNode());
        } else if(last instanceof OpenParenNode) {
            allowed.add(new ExpressionNode());
        } else if(last instanceof ExpressionNode) {
            allowed.add(new CloseParenNode());
        }
        
        return allowed;
    }

    @Override
    protected boolean isValid(IParseNode last, List<IParseNode> soFar) {
        return last instanceof CloseParenNode;
    }

    @Override
    public void loseWeight() {
        // remove ( )
        children.remove(0);
        children.remove(children.size() - 1);
    }

}
